import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';

enum Api {
  list = '/infra-service/fileConfig/page',
  get = '/infra-service/fileConfig/get',
  save = '/infra-service/fileConfig/save',
  edit = '/infra-service/fileConfig/update',
  delete = '/infra-service/fileConfig/delete',
  deleteBatch = '/system-service/fileConfig/batchDelete'
}

export const list = (params) => defHttp.get({url: Api.list, params});
export const getFileConfig = (params) => defHttp.get({url: Api.get, params});

export const deleteFileConfig = (params, handleSuccess) => {
  return defHttp.delete({url: Api.delete, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

export const batchDeleteFileConfig = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}

export const saveOrUpdateFileConfig = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}
